!function($) {
    window.BO = {
        Chrome: false,
        Safari: false,
        Firefox: false,
        Opera: false,
        IE: false,
        oldIE: false,
        newIE: false,
        iDevice: false,
        iPhone: false,
        iPad: false,
        android: false,
        name: "unkonwn",
        version: ""
    };

    (function() {
        "use strict";
        var uaInfo = navigator.userAgent;
        BO.getUAInfo = function() {
            return uaInfo
        }
        ;
        BO.init = function() {
            BO.detectBrowser();
            BO.detectDevice()
        }
        ;
        BO.detectBrowser = function() {
            var regF = /Firefox[\/\s](\d+\.\d+)/
              , regO = /Opera|OPR[\/\s](\d+\.\d+)/
              , regI = /MSIE[\/\s](\d+\.\d+)/
              , regC = /Chrome[\/\s](\d+\.\d+)/
              , regS = /Safari[\/\s](\d+\.\d+)/
              , regIn = /rv[\:\s](\d+\.\d+).*like Gecko/;
            BO.Firefox = regF.test(uaInfo);
            BO.Opera = regO.test(uaInfo);
            BO.Chrome = regC.test(uaInfo);
            BO.Safari = !BO.Chrome && regS.test(uaInfo);
            BO.newIE = regIn.test(uaInfo);
            BO.IE = BO.newIE || regI.test(uaInfo);
            BO.oldIE = BO.IE && !BO.newIE && Number(uaInfo.match(regI)[1]) < 9;
            var regSV = /Version\/(\d+.\d+.\d+)/;
            BO.Chrome && (BO.name = "Chrome") && (BO.version = uaInfo.match(regC) && uaInfo.match(regC)[1]);
            BO.Firefox && (BO.name = "Firefox") && (BO.version = uaInfo.match(regF) && uaInfo.match(regF)[1]);
            BO.Safari && (BO.name = "Safari") && (BO.version = uaInfo.match(regSV) && uaInfo.match(regSV)[1]);
            BO.Opera && (BO.name = "Opera") && (BO.version = uaInfo.match(regO) && uaInfo.match(regO)[1]);
            BO.IE && (BO.name = "IE") && (BO.version = BO.newIE ? uaInfo.match(regIn) && uaInfo.match(regIn)[1] : (uaInfo.match(regI) && uaInfo.match(regI))[1]);
            BO.webkit = !(BO.Firefox || BO.Opera || BO.IE)
        }
        ;
        BO.detectDevice = function() {
            var ua = uaInfo.toLowerCase();
            BO.android = ua.indexOf("android") > -1;
            /iPad/i.test(uaInfo) && (BO.iPad = true) && (BO.iDevice = true);
            /iPhone|iPod/i.test(uaInfo) && (BO.iPhone = true) && (BO.iDevice = true)
        }
    }
    )();
    
    $.fn.scrollUnique = function() {
        return $(this).each(function() {
            var eventType = "mousewheel";
            if (document.mozHidden !== undefined) {
                eventType = "DOMMouseScroll"
            }
            $(this).on(eventType, function(event) {
                var scrollTop = this.scrollTop
                  , scrollHeight = this.scrollHeight
                  , height = this.clientHeight;
                if ("wheelDeltaX"in event.originalEvent && event.originalEvent.wheelDeltaX !== 0)
                    return;
                if ("deltaX"in event.originalEvent && event.originalEvent.deltaX !== 0)
                    return;
                if ("axis"in event.originalEvent && event.originalEvent.axis === event.originalEvent.HORIZONTAL_AXIS)
                    return;
                var delta = event.originalEvent.wheelDelta ? event.originalEvent.wheelDelta : -(event.originalEvent.detail || 0);
                delta = delta / 5;
                if (delta > 0 && scrollTop <= delta || delta < 0 && scrollHeight - height - scrollTop <= -1 * delta) {
                    this.scrollTop = delta > 0 ? 0 : scrollHeight;
                    event.preventDefault()
                }
            })
        })
    };
    $(function() {
        BO.init();
        BO.oldIE && $("body").addClass("oldIE");
        BO.iDevice && $("body").addClass("Mobile");
        if (BO.oldIE && !localStorage.getItem("hideCompatible")) {
            $("body").addClass("Compatible")
        }
        var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
          , win_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
        var $frame = $("body");
        $(window).scroll(function(event) {
            if (!$("#header").hasClass("loaded")) {
                return
            }
            var currTop = $(window).scrollTop();
            if (currTop <= 30) {
                $frame.removeClass("scrolled")
            } else {
                $frame.addClass("scrolled")
            }
            if (currTop > win_height) {
                $(".float-sidebar").addClass("show-totop")
            } else {
                $(".float-sidebar").removeClass("show-totop")
            }
            $(".float-sidebar").removeClass("show");
            if ($(".footer-nav").css("visibility") === "hidden") {
                endCustomer()
            }
        });
        if (win_width < 1024) {
            $(".float-sidebar").on("click", ".shown-btn", function(event) {
                $(this).closest(".float-sidebar").addClass("show")
            });
            $(".help-header").addClass("hide")
        }
        var $header = $("#header");
        function setSubNav() {
            $(".subnav-layer").each(function(index, el) {
                $(this).css("top", $(this).height() * -1)
            })
        }
        headerFun();
        function headerFun() {
            $header.addClass("loaded");
            if (win_width < 1024) {
                $(".help-header .navigation .nav .nav-item").removeClass("hide")
            }
            var selIndex = String($header.data("on")).split(",");
            $header.find(".nav-item").eq(selIndex[0]).addClass("action").find(".sub-item").eq(selIndex[1]).addClass("action");
            $(".compatibility .close-large").on("click", function(event) {
                $("body").removeClass("Compatible");
                localStorage.setItem("hideCompatible", true)
            });
            if ($(".header-banner").length > 0) {
                var imgSrc = "";
                if (win_width >= 800) {
                    imgSrc = $(".header-banner-bg img.pc-bg").attr("src")
                } else {
                    imgSrc = $(".header-banner-bg img.mb-bg").attr("src")
                }
                $(".header-banner .header-banner-bg").css("background-image", "url(" + imgSrc + ")");
                $(".header-banner .close-large").on("click", function(event) {
                    $("body").removeClass("has-header-banner")
                })
            }
            $(window).scroll();
            $(".poster-actions-btns").clone().appendTo(".head-tools");
            var langTime;
            $header.find(".tool-item.tool-lang, .tool-item.user-info").mouseenter(function(e) {
                clearTimeout(langTime);
                var $this = $(this);
                langTime = setTimeout(function() {
                    $this.addClass("show");
                    $header.find(".tool-item.search").removeClass("show-search").find(".i-search").removeClass("on");
                    $navMain.removeClass("show");
                    $header.removeClass("show-menu")
                }, 200)
            }).mouseleave(function(e) {
                var $this = $(this);
                clearTimeout(langTime);
                setTimeout(function() {
                    $this.removeClass("show")
                }, 200)
            });
            $(".topbar-list li").hover(function() {
                var _this = $(this)
                  , target = _this.data("target")
                  , $con = _this.closest(".all-nav");
                _this.addClass("active").siblings("li").removeClass("active");
                if (target) {
                    $con.find(".menu-boxs." + target + "").addClass("show").siblings(".menu-boxs").removeClass("show");
                    $con.find(".nav-ing").removeClass("ing")
                } else {
                    $con.find(".nav-ing").addClass("ing").find(".menu-boxs").removeClass("show")
                }
            })
        }
        
        $(document).on("mouseenter", ".js-title", function() {
            if (this.scrollWidth > this.offsetWidth || this.scrollHeight > this.offsetHeight) {
                $(this).attr("title", $.trim($(this).text()))
            } else {
                $(this).attr("title", "")
            }
        });
        $frame.on("click", ".aui-button[disabled]", function(e) {
            e.preventDefault()
        });
        function $parseQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2])
            } else {
                return null
            }
        }
        if ($parseQueryString("fromacct")) {
            var fromacct = $parseQueryString("fromacct");
            var tmpEle = $("<div></div>");
            tmpEle.text(fromacct);
            fromacct = tmpEle.html();
            window.$usiteUtil.setCookie("h_fromacct", fromacct, 30)
        }
    });
   
}(jQuery);
